Ext.onReady(function () {

    initUI();


});

function initUI()
{

    let centerTabPanel=Ext.create('Ext.tab.Panel',{
        border:false,
        activeTab:0,
        items:[{
            id:'t_desk',
            border:false,
            title:'桌面',
            html:"桌面信息"
        }]
    });

    let student_treePanel=Ext.create('Ext.tree.Panel',{
        rootVisible: false,
        border:false,
        root:{
            children:[{
                text:'学生信息管理',
                leaf:false,
                expanded:true,
                children:[{
                    text:'学生管理',
                    id:'node_stu_manage',

                    leaf:true
                },{
                    text:'班级管理',
                    id:'node_class_manage',
                    leaf:true
                }]
            }]
        },
        listeners:{ itemclick : student_treePanel_click }
    });

    function student_treePanel_click(view, record)
    {
       if(record.get('leaf'))
       {
            let id=record.get('id');
            if(Ext.getCmp(id))
            {
                centerTabPanel.setActiveTab(id);
            }
            else
            {
                let currentGridPanel=null;
                if(id=='node_stu_manage')
                    currentGridPanel=student_list();
                else if(id=='node_class_manage')
                    currentGridPanel=(class_list());

                let currentPanel=Ext.create('Ext.panel.Panel',{
                    border:false,
                    id:record.data.id,
                    title:record.data.text,
                    layout:'fit',
                    closable:true,
                    items:currentGridPanel
                });
                centerTabPanel.add(currentPanel)
                centerTabPanel.setActiveTab(currentPanel);
            }
       }

    }

    let sys_treePanel=Ext.create('Ext.tree.Panel',{
        rootVisible: false,
        border:false,
        root:{
            children:[{
                text:'系统管理',
                leaf:false,
                expanded:true,
                children:[{
                    text:'系统设置',
                    leaf:true
                }]
            }]
        }
    });

    let westPanel=Ext.create('Ext.panel.Panel',{
        layout:'accordion',
        border:false,
        items:[{
            border:false,
            title:'学生管理',
            items:student_treePanel
        },{
            border:false,
            title:'系统设置',
            items:sys_treePanel
        }]
    });

    Ext.create('Ext.container.Viewport',{
        layout:'border',
        padding:'0 5 5 5',
        items:[{
            region:'north',
            border:false,
            bbar: [{
                xtype:'tbtext',
                text:'WELCOME TO STUDENT MANAGE SYSTEM'
            },'->',{
                iconCls:'btn-user',
                text:'管理员'
            },{
                iconCls:'btn-primary',
                text:'首选项',
                menu:[{
                    text:'用户信息',
                    iconCls:'btn-user'
                },{
                    text:'修改密码',
                    iconCls:'btn-modify-pwd'
                }]
            },{
                iconCls:'btn-loginout',
                text:'安全退出'
            }]
        },{
            region:'west',
            width:200,
            split:true,
            collapsible: true, // 支持该区域的展开和折叠
            title:'功能导航',
            layout:'fit',
            border:true,
            items:[westPanel]
        },{
            region:'center',
            border:false,
            layout:'fit',
            items:centerTabPanel
        },{
            region:'south',
            border:false,
            bbar:[{
                xtype:'tbtext',
                text:'Powered By Turing'
            },{
                xtype:"tbfill"
            },{
                text:'技术支持：图灵课堂'
            }]
        }]

    });
}